Series

Series is a one-dimensional labeled array capable of holding any data type (integers, strings, floating point numbers, Python objects, etc.). The axis labels are collectively referred to as the index.

documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html


In [1]:
import pandas as pd
import numpy as np
Create series from NumPy array

number of labels in 'index' must be the same as the number of elements in array


In [ ]:
my_simple_series = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
my_simple_series

In [3]:
my_simple_series.index


Out[3]:
Index(['a', 'b', 'c', 'd', 'e'], dtype='object')
Create series from NumPy array, without explicit index

In [ ]:


In [ ]:
Access a series like a NumPy array

In [ ]:

Create series from Python dictionary

In [ ]:
my_dictionary = {'a' : 45., 'b' : -19.5, 'c' : 4444}
my_second_series = pd.Series(my_dictionary)
my_second_series

In [ ]:
Access a series like a dictionary

In [ ]:

note order in display; same as order in "index"

note NaN


In [ ]:
pd.Series(my_dictionary, index=['b', 'c', 'd', 'a'])

In [ ]:


In [ ]:
unknown = my_second_series.get('f')
type(unknown)
Create series from scalar

If data is a scalar value, an index must be provided. The value will be repeated to match the length of index


In [ ]:
pd.Series(5., index=['a', 'b', 'c', 'd', 'e'])